package org.gp.tringes;

import java.sql.Date;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.Observable;

public class GestorIGAnadirTrineo extends Observable{
	
	private static GestorIGAnadirTrineo miGestorIGAnadirTrineo = new GestorIGAnadirTrineo();
	
	private GestorIGAnadirTrineo(){}
	
	public static GestorIGAnadirTrineo getGestorIGAnadirTrineo(){
		return miGestorIGAnadirTrineo;
	}
	
	public Boolean comprobarLongitudMatr(String pMatr){
    	if(pMatr.length() == 0 || pMatr.length() > 20){
    		return false;
    	}else{
    		return true;
    	}
    }
	
	public Boolean comprobarLongitudFabr(String pFabr){
    	if(pFabr.length() == 0 || pFabr.length() > 20){
    		return false;
    	}else{
    		return true;
    	}
    }
	
	public Boolean existeTrineo(String pMatr) throws SQLException{
		//Hacer un SELECT con pNombre. Si no hay resultados, continuamos devolviendo false. Si hay, devolvemos true
		ResultSet rs = GestorBD.getInstance().consulta("select * from trineo where id='"+pMatr+"'");
		Boolean result = rs.next();
		GestorBD.getInstance().cerrarConsulta(rs);
		if(result){
			return true;
		}else{
			return false;
		}
	}
	
	public void insertarTrineo(String pMatr, String pFabr, Date pFechFabr, Integer pIdClub) throws SQLException{
		
    	GestorBD.getInstance().insertar("insert into trineo(id,fabricante,fechaFabricacion,idClub) values ('"+pMatr+"','"+pFabr+"','"+pFechFabr+"',"+pIdClub+")");
    	
	}
}
